package com.facebook.commands.share 
{
	import com.facebook.Events.FacebookEvent;
	import com.facebook.commands.FacebookCall;
	import com.facebook.commands.query.Query;
	import com.facebook.data.FacebookData;
	import com.facebook.errors.FacebookError;
	import com.facebook.utils.FacebookConnectUtils;

	import flash.external.ExternalInterface;

	/**
	 * @author Ben Smith
	 */
	public class Share extends FacebookCall
	{

		static public const METHOD : String = "stream.share"
		static public const FUNCTION_CALL : String = "FB.ui"
		
		private var _url:String

		public function Share(shareURL:String="yahoo.com")
		{
			_url=shareURL;
		}

		override public function makeCall(format : String = "JSON") : FacebookCall
		{
		
			var _jsCall : String = FUNCTION_CALL + '({method:\''+METHOD+"\',u:\'" +encodeURI(_url)+"\'}," + FacebookConnectUtils.createAnonymousCallFunction(); 
			FacebookConnectUtils.registerCall(this);
			trace(_jsCall)
			ExternalInterface.call(_jsCall);
			
			return this
		}

		override public function quickTrace() : void
		{
			trace('there is nothing to display')
		}

		override public function handleResult(result : FacebookData) : void 
		{

		dispatchEvent(new FacebookEvent(FacebookEvent.COMPLETE, false, false, true, result));
			
		}

		override 	public function handleError(error : FacebookError) : void 
		{
		
			dispatchEvent(new FacebookEvent(FacebookEvent.COMPLETE, false, false, false, null, error));
		}

		override public function toString() : String
		{
			return Query.METHOD
		}
	}
}
